package com.yuanqunsoft.alimigration.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.yuanqunsoft.alimigration.bean.AlertBean;
import com.yuanqunsoft.alimigration.dao.IAlertDao;
import com.yuanqunsoft.alimigration.dao.support.Page;
import com.yuanqunsoft.alimigration.model.Alert;

public class AlertDaoImpl extends HibernateDaoSupport implements IAlertDao {

    @Override
    public void save(Alert instance) {
        try {
            getHibernateTemplate().save(instance);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    @Override
    public void delete(Alert instance) {
        try {
            getHibernateTemplate().delete(instance);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    @Override
    public Alert findById(Integer id) {
        try {
            return (Alert) getHibernateTemplate().get(Alert.class, id);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    @Override
    public List findByReportId(Integer reportId) {
        try {
            String query = "from Alert a where a.report.repId=?";
            return getHibernateTemplate().find(query, reportId);
        } catch (RuntimeException re) {
            throw re;
        }
    }

    @Override
    public List findByExample(Alert instance) {
        try {
            List<Alert> result = getHibernateTemplate().findByExample(instance);
            return result;
        } catch (RuntimeException re) {
            throw re;
        }
    }

    @Override
    public boolean hqlExcute(String hql, Object... values) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public List<Alert> hqlQuery(String hql, Object... values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public <Alert> Page<Alert> pagedQuery(String hql, int pageNo, int pageSize, Object... values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Page<Alert> pagedQueryByStartNo(String hql, int startNo, int pageSize, Object... values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<Alert> findByNamedParams(String hql, String[] paramNames, Object... values) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void deleteByReportId(Integer id) {
        try {
            List<Alert> alertList = this.findByReportId(id);
            for (Alert a : alertList) {
                this.delete(a);
            }
        } catch (RuntimeException re) {
            throw re;
        }
    }

}
